// 读取两个"text/csv"节点输入数据
import { cloneDeep } from 'lodash'

export default {
  inject: ['root','flowchartId'],
  data() {
    return {
      formModel: {},
      leftInputData: [],
      rightInputData: []
    }
  },
  created() {
    console.log('create two csv input node')
    const { getSelected, save, find } = this.root.propsAPI
    const formModel = getSelected()[0].getModel()
    this.formModel = Object.assign({}, cloneDeep(formModel))
    const flowchartData = save()
    if (!flowchartData.edges) {
      return
    }
    const inputEdges = flowchartData.edges.filter(edge => {
      return edge.target === formModel.id
    })
    // 拷贝左表输入信息
    if (inputEdges.length > 0) {
      const leftInputEdge = inputEdges[0]
      const leftInputNodeModel = find(leftInputEdge.source).getModel()
      if (leftInputNodeModel.executed) {
        this.formModel.config.leftInputNode = leftInputEdge.source
        this.leftInputData = leftInputNodeModel.config.output
      }
    }
    // 拷贝右表输入信息
    if (inputEdges.length > 1) {
      const rightInputEdge = inputEdges[1]
      const rightInputNodeModel = find(rightInputEdge.source).getModel()
      if (rightInputNodeModel.executed) {
        this.formModel.config.rightInputNode = rightInputEdge.source
        this.rightInputData = rightInputNodeModel.config.output
      }
    }
  }
}
